/*
 * Project: Sudoku Explainer
 * Copyright (C) 2006-2007 Nicolas Juillerat
 * 
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.rules.uniqueness;

import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import com.onegravity.sudoku.solver.HintResource;
import com.onegravity.sudoku.solver.HintType;
import com.onegravity.sudoku.solver.R;
import com.onegravity.sudoku.solver.core.Rule;
import com.onegravity.sudoku.solver.data.Cell;
import com.onegravity.sudoku.solver.data.ImmutableCell;
import com.onegravity.sudoku.solver.util.HtmlLoader;
import com.onegravity.sudoku.solver.util.ValuesFormatter;

public class Bug1Hint extends BugHint implements Rule {

	private static final long serialVersionUID = 1721922170013801515L;
	
	private final Cell bugCell;
	private final BitSet bugValues;

    public Bug1Hint(Map<Cell, BitSet> removablePotentials, Cell bugCell, BitSet bugValues) {
        super(removablePotentials);
        this.bugCell = bugCell;
        this.bugValues = bugValues;
    }

    @Override
    public Collection<Cell> getSelectedCells(HintType hintType) {
    	return (hintType!=HintType.SMALL_CLUE) ? Collections.singletonList(bugCell) : null;
    }

    @Override
    public Map<Cell, BitSet> getAddedPotentials(HintType hintType, int viewNum) {
        return (hintType==HintType.HINT) ? Collections.singletonMap(bugCell, bugValues) : null;
    }

    @Override
    public Map<ImmutableCell, BitSet> getRemovedPotentials(HintType hintType) {
        return (hintType==HintType.HINT) ? super.getRemovedPotentials(hintType) : null;
    }

    @Override
    public double getDifficulty() {
        return 5.6;
    }

    @Override
    protected HintResource getResource() {
    	return HintResource.BUG_1;
    }

    @Override
    protected int getType() {
    	return 1;
    }

    @Override
    protected String getAppendixString() {
    	return bugCell.toString();
    }

    @Override
    public String getHintHtml(HintType hintType) {
        String andString = HintResource.getString(R.string.and);
        String orString = HintResource.getString(R.string.or);
        String result = HtmlLoader.loadHtml(HintResource.BUG_1.hint(hintType));
        String andExtra = ValuesFormatter.formatValues(bugValues, " " + andString + " "); //$NON-NLS-1$ //$NON-NLS-2$
        String orExtra = ValuesFormatter.formatValues(bugValues, " " + orString + " "); //$NON-NLS-1$ //$NON-NLS-2$
        BitSet removable = super.getRemovablePotentials().get(bugCell);
        String remList = ValuesFormatter.formatValues(removable, " " + andString + " "); //$NON-NLS-1$ //$NON-NLS-2$
        result = HtmlLoader.format(result, andExtra, bugCell, orExtra, remList);
        return result;
    }

}